<template>
	<view class="page">
    <view class="top">
      <u-button shape="circle" text="环保回收旧衣服助力低碳生活" color="linear-gradient(to right, rgb(40, 40, 38), rgb(230, 210, 200))"></u-button>
      <img style="width: 100vw;height: 200px;" src="http://127.0.0.1:3000/image/011.jpg" alt="">
      <u-line-progress :percentage="progress" activeColor="#423b33"></u-line-progress>
    </view>
    <view class="main">
      <view class="mainBox">用户名：{{this.recycleOrderList.ordername}}</view>
      <view class="mainBox">用户电话：{{this.recycleOrderList.phone}}</view>
      <view class="mainBox">家庭地址：{{this.recycleOrderList.address}}</view>
      <view class="mainBox">预约日期：{{this.recycleOrderList.dataSpan}}</view>
      <view class="mainBox">预约时间：{{this.recycleOrderList.timeSpan}}</view>
      <u-button class="mainBtn" type="primary" icon="checkbox-mark" text="确认接单" @click="goMy"></u-button>
    </view>
    <view>

    </view>
	</view>
</template>

<script>
  import { baseUrl } from '@/config'
export default {
	data() {
		return {
      progress:0,
      orderIndex:1,
      id:0,
      status:1,
      recycleOrderList:[]
		};
	},
	onShow() {
	this.getProgress(),
  this.getRecycleOrder()
	},
  onReady() {

	},
	methods: {
    goMy(){
      uni.request({
          url:baseUrl+"/v1/recycle/orderUpdate",
          method: 'POST',
          header: {
						'Content-Type': 'application/x-www-form-urlencoded'
					},
 					data: {
 						id: this.id,
            status:this.status
 					},
          success:(res)=>{
            if (res.data.code == 200) {
              this.id =  uni.getStorageSync('user').data[0].id
              uni.request({
 					        url:baseUrl+'/v1/user/idSearch',
 					        data: {
 						        id: this.id,
 					        },
                  success:(res)=>{
                    let r = res.data.data[0].doller
                    this.doller =parseInt(r) + 10
                    uni.request({
                      method: 'POST',
                      header: {
                      'Content-Type': 'application/x-www-form-urlencoded'
                      },
                      url: baseUrl+'/v1/user/userUpdate',
                    data:{
                      id : this.id,
                      doller:this.doller
                    },
                    success: () => {
                      uni.showToast({
                      title: '接单成功',
                      duration: 1000
                    });
                    setTimeout(function() {
                uni.navigateTo({
	                      url: '/pages/recycle-order/index'
                      });
				      }, 1500)
                      }
          });
                  }
 				      })  


                  
 				} else {
 					uni.showToast({
 						title: "修改失败!",
 						icon: 'none',
 						duration: 2000
 					})
 				}
          }
 				})
    },
    getRecycleOrder(){
      this.orderIndex =uni.getStorageSync('recycle_key');
      uni.request({
                      url: baseUrl+'/v1/recycle/orderSearch',
                      success: (res) => {
                        this.recycleOrderList = res.data.data[this.orderIndex]
                        // this.phone = res.data.data[this.orderIndex].phone
                        this.id = res.data.data[this.orderIndex].id
                      }
                });
    },
    getProgress(){
     setTimeout(() => {
					this.progress=10
				}, 1000);
        setTimeout(() => {
					this.progress=50
				}, 2000);
        setTimeout(() => {
					this.progress=100
				}, 2500);  
      },
}
};
</script>

<style lang="scss" scoped>
.page{
  .main{
    border: 4rpx solid #6b6766;
    height:400px;
    margin: 30px;
    box-shadow: 0 6upx 8upx 8upx rgba(63, 62, 60, 0.2);
    position: relative;
    .mainBox{
      margin: 10px 5px;
      padding: 10px 10px;
      border: 2px solid #2b2a28;
      border-radius: 20px;
      
    }
    .mainBtn{
 
      background-color:#363435 ;
      border-radius: 20px;
      position: absolute;
      width: 80%;
      left: 30px;
      bottom: 10px;
    }
  }
}
</style>
